package com.education.quartz.job;

import com.education.quartz.manage.ScheduleManage;
import com.education.welco.pojo.STheoryClassroom;
import com.education.welco.service.ISTheoryClassroomService;
import lombok.extern.slf4j.Slf4j;
import org.quartz.*;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @Author: liftsail
 * @Date: 2022/11/22 16:04
 * @Description: 不积跬步无以至千里
 */
@Slf4j
@DisallowConcurrentExecution //不允许并发执行
public class CourseStateJob implements Job {

    @Autowired
    private ISTheoryClassroomService theoryClassroomService;

    @Autowired
    private ScheduleManage scheduleManage;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        TriggerKey triggerKey = jobExecutionContext.getTrigger().getKey();
        JobKey jobKey = jobExecutionContext.getJobDetail().getKey();
        JobDataMap jobDataMap = jobExecutionContext.getTrigger().getJobDataMap();
        Integer courseId = (Integer) jobDataMap.get("courseId");
        //根据课堂id修改直播课的状态为已结束
        STheoryClassroom sTheoryClassroom = new STheoryClassroom();
        sTheoryClassroom.setId(courseId);
        sTheoryClassroom.setStatus("2");
        theoryClassroomService.updateSTheoryClassroom(sTheoryClassroom);
        //int i = theoryClassroomService.test01(courseId);
        //任务完成删除定时任务
        scheduleManage.deleteSchedule(jobKey, triggerKey);
    }
}
